package com.smartscreen.schedulemanage.controller;

import com.smartscreen.common.response.ApiResponse;
import com.smartscreen.schedulemanage.dto.UpdateTimetableSessionRequest;
import com.smartscreen.schedulemanage.entity.TimetableSession;
import com.smartscreen.schedulemanage.service.TimetableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/schedule")
public class TimetableController {
    
    @Autowired
    private TimetableService timetableService;
    
    @PostMapping("/classes/{classId}/timetable/import")
    public ApiResponse<Void> importClassTimetable(
            @PathVariable String classId,
            @RequestParam("file") MultipartFile file) {
        String message = timetableService.importClassTimetable(classId, file);
        return new ApiResponse<>(200, message);
    }
    
    @GetMapping("/classes/{classId}/timetable")
    public ApiResponse<Map<String, Object>> getClassTimetable(
            @PathVariable String classId,
            @RequestParam String termId) {
        Map<String,Object> timetable = timetableService.getClassTimetable(classId, termId);
        return ApiResponse.success(timetable);
    }
    
    @GetMapping("/teachers/{teacherId}/timetable")
    public ApiResponse<Map<String, Object>> getTeacherTimetable(
            @PathVariable String teacherId,
            @RequestParam String termId) {
        Map<String, Object> timetable = timetableService.getTeacherTimetable(teacherId, termId);
        return ApiResponse.success(timetable);
    }
    
    @PutMapping("/timetable/sessions/{sessionId}")
    public ApiResponse<Void> updateTimetableSession(
            @PathVariable String sessionId,
            @RequestBody UpdateTimetableSessionRequest request) {
        timetableService.updateTimetableSession(sessionId, request);
        return new ApiResponse<>(200, "课程信息更新成功");
    }
}